GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f09db0...a12c7a )
by Florian
01:09
created

Line.getId   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
1
/*jslint
2
  regexp: true
3
  indent: 4
4
*/
5
6
/*global
7
  $, google, theMarkers, id2alpha, Cookies, Coordinates, TxtOverlay
8
*/
9
10
function Line(themap, id, source, target) {
11
    'use strict';
12
13
    this.m_map = themap;
14
    this.m_id = id;
15
    this.m_lineMapObject = null;
16
    this.m_source = -1;
17
    this.m_target = -1;
18
    this.m_distanceLabel = null;
19
20
    $('#dynLineDiv').append(
21
        "<div id=\"dynLine" + id + "\">" +
22
            "<table style=\"width: 100%\">" +
23
            "<tr>" +
24
            "<td>" +
25
            "<select id=\"dynlinesource" + id + "\" class=\"my-small-select\" data-i18n=\"[title]sidebar.lines.source\" onchange=\"Lines.selectLineSource(" + id + ")\"><option value=\"-1\">?</option></select>" +
26
            "&nbsp;&rarr;&nbsp;" +
27
            "<select id=\"dynlinetarget" + id + "\" class=\"my-small-select\" data-i18n=\"[title]sidebar.lines.destination\" onchange=\"Lines.selectLineTarget(" + id + ")\"><option value=\"-1\">?</option></select>" +
28
            "</td>" +
29
            "<td>" +
30
            "<button class=\"my-button btn btn-mini btn-danger\" style=\"float: right\" data-i18n=\"[title]sidebar.lines.delete_line\" type=\"button\" onClick=\"trackLine('delete'); Lines.deleteLine(" + id + ")\"><i class=\"fa fa-trash-o\"></i></button>" +
31
            "<div>" +
32
            "</div>" +
33
            "</td>" +
34
            "</tr>" +
35
            "<tr><td colspan=\"2\"><i class=\"fa fa-arrows-h\"></i> <span id=\"dynlinedist" + id + "\">n/a</span> <i class=\"fa fa-compass\"></i> <span id=\"dynlineangle" + id + "\">n/a</span></td></tr>" +
36
            "</table>" +
37
            "</div>"
38
    );
39
40
    this.updateLists();
41
    this.setSource(source);
42
    this.setTarget(target);
43
}
44
45
46
Line.prototype.m_map = null;
47
Line.prototype.m_id = -1;
48
Line.prototype.m_lineMapObject = null;
49
Line.prototype.m_source = -1;
50
Line.prototype.m_target = -1;
51
Line.prototype.m_distanceLabel = null;
52
53
54
Line.prototype.getId = function () {
55
    'use strict';
56
57
    return this.m_id;
58
};
59
60
61
Line.prototype.clearMapObject = function () {
62
    'use strict';
63
64
    if (this.m_lineMapObject) {
65
        this.m_lineMapObject.setMap(null);
66
        this.m_lineMapObject = null;
67
    }
68
69
    if (this.m_distanceLabel) {
70
        this.m_distanceLabel.setMap(null);
71
        this.m_distanceLabel = null;
72
    }
73
};
74
75
76
Line.prototype.getEndpointsString = function () {
77
    'use strict';
78
79
    return id2alpha(this.m_source) + ":" + id2alpha(this.m_target);
80
};
81
82
83
Line.prototype.setSource = function (markerId) {
84
    'use strict';
85
86
    if (markerId !== this.m_source) {
87
        this.m_source = markerId;
88
        this.update();
89
        $("#dynlinesource" + this.m_id + " > option[value=" + markerId + "]").attr("selected", "selected");
90
    }
91
};
92
93
94
Line.prototype.setTarget = function (markerId) {
95
    'use strict';
96
97
    if (markerId !== this.m_target) {
98
        this.m_target = markerId;
99
        this.update();
100
        $("#dynlinetarget" + this.m_id + " > option[value=" + markerId + "]").attr("selected", "selected");
101
    }
102
};
103
104
105
Line.prototype.update = function () {
106
    'use strict';
107
108
    if (this.m_source === -1 || this.m_target === -1) {
109
        this.clearMapObject();
110
111
        $("#dynlinedist" + this.m_id).html("n/a");
112
        $("#dynlineangle" + this.m_id).html("n/a");
113
114
        return;
115
    }
116
117
    var pos1 = theMarkers.getById(this.m_source).getPosition(),
118
        pos2 = theMarkers.getById(this.m_target).getPosition(),
119
        path = new google.maps.MVCArray(),
120
        dist_angle = { dist: 0, angle: 0 },
121
        centerPos;
122
123
    if (!this.m_lineMapObject) {
124
        this.m_lineMapObject = new google.maps.Polyline({
125
            strokeColor: '#ff0000',
126
            strokeWeight: 2,
127
            strokeOpacity: 0.7,
128
            geodesic: true,
129
            icons: [{
130
                icon: {
131
                    path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
132
                },
133
                repeat: '0'
134
            }]
135
        });
136
        this.m_lineMapObject.setMap(this.m_map);
137
        this.m_distanceLabel = new TxtOverlay(pos2, "n/a", "mapDistanceLabel", this.m_map);
138
    }
139
140
    path.push(pos1);
141
    path.push(pos2);
142
    this.m_lineMapObject.setPath(path);
143
    if (this.m_source !== this.m_target) {
144
        dist_angle = Coordinates.dist_angle_geodesic(pos1, pos2);
145
    }
146
147
    centerPos = Coordinates.projection_geodesic(pos1, dist_angle.angle, 0.5 * dist_angle.dist);
148
    this.m_distanceLabel.setPos(centerPos);
149
    this.m_distanceLabel.setText(dist_angle.dist.toFixed() + "m");
150
151
    if (dist_angle.dist <= 0) {
152
        $("#dynlinedist" + this.m_id).html("0m");
153
        $("#dynlineangle" + this.m_id).html("n/a");
154
    } else {
155
        $("#dynlinedist" + this.m_id).html(dist_angle.dist.toFixed() + "m");
156
        $("#dynlineangle" + this.m_id).html(dist_angle.angle.toFixed(1) + "°");
157
    }
158
};
159
160
161
Line.prototype.updateMarkerMoved = function (markerId) {
162
    'use strict';
163
164
    if (this.m_source === markerId || this.m_target === markerId) {
165
        this.update();
166
    }
167
};
168
169
170
Line.prototype.updateMarkerRemoved = function (markerId) {
171
    'use strict';
172
173
    if (this.m_source === markerId) {
174
        this.m_source = -1;
175
        this.clearMapObject();
176
    }
177
178
    if (this.m_target === markerId) {
179
        this.m_target = -1;
180
        this.clearMapObject();
181
    }
182
183
    this.updateLists();
184
};
185
186
187
Line.prototype.updateMarkerAdded = function () {
188
    'use strict';
189
190
    this.updateLists();
191
};
192
193
194
Line.prototype.updateLists = function () {
195
    'use strict';
196
197
    var source = $('#dynlinesource' + this.m_id),
198
        target = $('#dynlinetarget' + this.m_id),
199
        i,
200
        m;
201
202
    source.empty();
203
    target.empty();
204
205
    source.append('<option value="-1">?</option>');
206
    target.append('<option value="-1">?</option>');
207
208
    for (i = 0; i < theMarkers.getSize(); i = i + 1) {
209
        m = theMarkers.getById(i);
210
        if (!m.isFree()) {
211
            source.append('<option value="' + i + '">' + m.getAlpha() + '</option>');
212
            target.append('<option value="' + i + '">' + m.getAlpha() + '</option>');
213
        }
214
    }
215
216
    $("#dynlinesource" + this.m_id + " > option[value=" + this.m_source + "]").attr("selected", "selected");
217
    $("#dynlinetarget" + this.m_id + " > option[value=" + this.m_target + "]").attr("selected", "selected");
218
};
219
220
221
var Lines = {};
222
Lines.m_map = null;
223
Lines.m_nextLineId = 0;
224
Lines.m_lines = [];
225
226
227
Lines.init = function (themap) {
228
    'use strict';
229
230
    Lines.m_map = themap;
231
    Lines.m_nextLineId = 0;
232
    Lines.m_lines = [];
233
};
234
235
236
Lines.newLine = function (source, target) {
237
    'use strict';
238
239
    this.m_lines.push(new Line(Lines.m_map, this.m_nextLineId, source, target));
240
    this.m_nextLineId += 1;
241
    this.saveCookie();
242
};
243
244
245
Lines.getLineIndex = function (id) {
246
    'use strict';
247
248
    var index, line;
249
250
    for (index = 0; index < this.m_lines.length; index += 1) {
251
        line = this.m_lines[index];
252
        if (line && line.getId() === id) {
253
            return index;
254
        }
255
    }
256
257
    return -1;
258
};
259
260
261
Lines.getLineById = function (id) {
262
    'use strict';
263
264
    var index = this.getLineIndex(id);
265
    if (index < 0) {
266
        return null;
267
    }
268
    return this.m_lines[index];
269
};
270
271
272
Lines.getLinesText = function () {
273
    'use strict';
274
275
    var a = [];
276
    this.m_lines.map(function (line) {
277
        if (line) {
278
            a.push(line.getEndpointsString());
279
        }
280
    });
281
    return a.join("*");
282
};
283
284
285
Lines.saveCookie = function () {
286
    'use strict';
287
288
    Cookies.set("lines", this.getLinesText(), {expires: 30});
289
};
290
291
292
Lines.selectLineSourceById = function (id, markerId) {
293
    'use strict';
294
295
    this.getLineById(id).setSource(markerId);
296
    this.saveCookie();
297
};
298
299
300
Lines.selectLineSource = function (id) {
301
    'use strict';
302
303
    var markerId = -1,
304
        opt = $("#dynlinesource" + id + " option:selected");
305
306
    if (opt) {
307
        markerId = parseInt(opt.val(), 10);
308
    }
309
310
    this.selectLineSourceById(id, markerId);
311
};
312
313
314
Lines.selectLineTargetById = function (id, markerId) {
315
    'use strict';
316
317
    this.getLineById(id).setTarget(markerId);
318
    this.saveCookie();
319
};
320
321
322
Lines.selectLineTarget = function (id) {
323
    'use strict';
324
325
    var markerId = -1,
326
        opt = $("#dynlinetarget" + id + " option:selected");
327
328
    if (opt) {
329
        markerId = parseInt(opt.val(), 10);
330
    }
331
332
    this.selectLineTargetById(id, markerId);
333
};
334
335
336
Lines.updateLinesMarkerMoved = function (markerId) {
337
    'use strict';
338
339
    this.m_lines.map(function (line) {
340
        if (line) {
341
            line.updateMarkerMoved(markerId);
342
        }
343
    });
344
};
345
346
347
Lines.updateLinesMarkerAdded = function () {
348
    'use strict';
349
350
    this.m_lines.map(function (line) {
351
        if (line) {
352
            line.updateMarkerAdded();
353
        }
354
    });
355
};
356
357
358
Lines.updateLinesMarkerRemoved = function (markerId) {
359
    'use strict';
360
361
    this.m_lines.map(function (line) {
362
        if (line) {
363
            line.updateMarkerRemoved(markerId);
364
        }
365
    });
366
    this.saveCookie();
367
};
368
369
370
Lines.updateLine = function (id) {
371
    'use strict';
372
373
    var index = this.getLineIndex(id);
374
    if (index < 0) {
375
        return;
376
    }
377
378
    this.m_lines[index].update();
379
};
380
381
382
Lines.deleteLine = function (id) {
383
    'use strict';
384
385
    $('#dynLine' + id).remove();
386
387
    var index = this.getLineIndex(id);
388
    if (index < 0 || !this.m_lines[index]) {
389
        return;
390
    }
391
392
    this.m_lines[index].clearMapObject();
393
    this.m_lines[index] = null;
394
395
    this.saveCookie();
396
};
397
398
399
Lines.deleteAllLines = function () {
400
    'use strict';
401
402
    var self = this;
403
    this.m_lines.map(function (line) {
404
        if (line) {
405
            self.deleteLine(line.getId());
406
        }
407
    });
408
};
409